import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state:{
		currentCityCode:"",
		currentCityName:"",
		openid:"",
		userInfo:{
			id:"",
			nickName:"",
			headImage:"",
			balance:0,
			frozenBalance:0
		},
		hasLogin: false,
	},
	mutations:{
		changeOpenid(state,n){
			state.openid = n;
		},
		changeUserInfo(state,n){
			state.hasLogin = true;
			state.userInfo = n;
			uni.setStorage({//缓存用户登陆状态
			    key: 'G_userInfo',  
			    data: n  
			}) 
		},
		changeCurrentCityCode(state,n){
			state.currentCityCode = n;
		},
		changeCurrentCityName(state,n){
			state.currentCityName = n;
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({  
                key: 'G_userInfo'  
            })
		}
	}
})

export default store